﻿using TraumaCenterSystem.Bll;
using TraumaCenterSystem.Core;
using TraumaCenterSystem.Model;
using TraumaCenterSystem.TraumaCenterManage;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Common;
using TraumaCenterSystem.Utils;

namespace TraumaCenterSystem.Areas.TraumaCenter.Controllers
{
    public class MedicalRecordsController : BaseController
    {
        // GET: /TraumaCenter/MedicalRecords/

        public ActionResult Index()
        {
            string patientId = Request.QueryString["patientId"];
            ViewBag.patientId = patientId;
            return View();
        }
        /// <summary>
        /// 创伤病历
        /// </summary>
        /// <returns></returns>
        public ActionResult Traumamr()
        {
            string pid = WebUtils.GetString("pid");
            ViewBag.patientId = pid;
            return View();
        }
        /// <summary>
        /// 创伤病历打印
        /// </summary>
        /// <returns></returns>
        public ActionResult TraumamrPrint()
        {
            string pid = WebUtils.GetString("pid");
            ViewBag.patientId = pid;
            return View();
        }
        /// <summary>
        /// 创伤病历数据
        /// </summary>
        /// <param name="patientid"></param>
        /// <returns></returns>
        public ActionResult GetTraumamr(string patientid)
        {
            OperateResult resultInfo = MedicalRecordsManager.Get_EpiduralHematoma(patientid);
            if (resultInfo.Result != 1) return Content(resultInfo.Body.ToString());
            string json = resultInfo.Body.ToString();
            TraumaCenterSystem.Model.GetEHMR PatHis = JsonConvert.DeserializeObject<GetEHMR>(json);
            return JsonDate(PatHis);
        }
        /// <summary>
        /// 创伤病历保存
        /// </summary>
        /// <param name="datajson"></param>
        /// <returns></returns>
        public ActionResult SaveTraumamr(string datajson = "")
        {
            OperateResult result = new OperateResult();
            if (!string.IsNullOrEmpty(datajson))
                result = MedicalRecordsManager.Set_EpiduralHematoma(datajson);
            return JsonDate(result);
        }

        /// <summary>
        /// 时间路径
        /// </summary>
        /// <returns></returns>
        public ActionResult Timepath()
        {
            string pid = WebUtils.GetString("pid");
            ViewBag.patientId = pid;
            return View();
        }

        /// <summary>
        /// 获取创伤时间路径数据
        /// </summary>
        /// <param name="patientid"></param>
        /// <returns></returns>
        public ActionResult Get_PatientTimePath(string patientid)
        {
            OperateResult resultInfo = MedicalRecordsManager.Get_PatientTimePath(patientid);
            if (resultInfo.Result != 1) return Content(resultInfo.Body.ToString());
            string json = resultInfo.Body.ToString();
            TraumaCenterSystem.Model.GetTimePath PatHis = JsonConvert.DeserializeObject<GetTimePath>(json);
            return JsonDate(PatHis);
        }
        /// <summary>
        /// 保存创伤时间路径数据
        /// </summary>
        /// <param name="datajson"></param>
        /// <returns></returns>
        public ActionResult SetExecutionDate(string datajson = "")
        {
            OperateResult result = new OperateResult();
            if (!string.IsNullOrEmpty(datajson))
                result = MedicalRecordsManager.Set_ExecutionDate(datajson);
            return JsonDate(result);
        }
    }
}
